
from config.config import HOST
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import BasePage
class CommercialPage(BasePage):
    """商机页面的操作"""
    url = "http://{}/crm/index.php?m=business".format(HOST)
    click_commercial_locaotr=(By.CSS_SELECTOR,'body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul:nth-child(1) > li:nth-child(3) > a')
    click_boost_locator = (By.LINK_TEXT,'推进')
    click_save_locator = (By.XPATH, '//*[@id="dialog-advance"]/form/table/tbody/tr[5]/td[2]/input[1]')
    stage_describe_locator = (By.XPATH, '//*[@id="dialog-advance"]/form/table/tbody/tr[4]/td[2]/textarea')
    tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')
    boost_tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')
    select_commercial_del_locator = (By.NAME, 'business_id[]')
    click_del_locaotr = (By.CSS_SELECTOR, '#delete')
    del_successful_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    click_add_commercial_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div > a')
    click_commercial_look_locator=(By.CSS_SELECTOR,'#form1 > table > tbody > tr > td:nth-child(12) > a:nth-child(1)')
    no_select_del_tips_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-error')
    no_select_search_locator=(By.CSS_SELECTOR,'#dosearch')
    input_search_content_locator=(By.CSS_SELECTOR,'#search')
    select_first_locator = (By.NAME, 'field')
    click_commercial_count_locator=(By.CSS_SELECTOR,'body > div.container > div.page-header > ul > li:nth-child(2) > a')

    def click_add_commercial(self):
        """点击添加商机"""
        self.driver.find_element(*self.click_add_commercial_locator).click()

    def click_commercial_look(self):
        """点击查看"""
        self.driver.find_element(*self.click_commercial_look_locator).click()

    def click_boost(self):
        """点击推进"""
        self.driver.find_element(*self.click_boost_locator).click()

    def input_stae_describe_specily(self,describe):
        """阶段描述包含特殊字符"""
        self.driver.find_element(*self.stage_describe_locator).send_keys(describe)

    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.click_save_locator).click()

    def select_commercial(self):
        """勾选商机"""
        self.driver.find_element(*self.select_commercial_del_locator).click()

    def click_del_btn(self):
        """点击删除"""
        self.driver.find_element(*self.click_del_locaotr).click()

    def alert_commercial_del(self):
        """跳出弹窗，点击确定"""
        self.driver.switch_to.alert.accept()

    def input_search_box_content(self,content):
        """填写搜索框内容"""
        self.driver.find_element(*self.input_search_content_locator).send_keys(content)

    def click_search_commercial(self):
        """点击搜索"""
        self.driver.find_element(*self.no_select_search_locator).click()

    def commercial_tips(self):
        """断言，点击删除成功字样"""
        tips=self.driver.find_element(*self.tips_locator).text
        return tips

    def boost_tips(self):
        """断言，推进成功字样"""
        boost_tips=self.driver.find_element(*self.boost_tips_locator).text
        return boost_tips

    def del_successful_tips(self):
        """断言，删除成功"""
        del_successful_tips=self.driver.find_element(*self.del_successful_tips_locator).text
        return del_successful_tips

    def no_select_del_tips(self):
        """断言，没有选择任何内容删除"""
        no_select_del_tips=self.driver.find_element(*self.no_select_del_tips_locator).text
        return no_select_del_tips


    def select_first_commercial(self):
        """选择第一个筛选条件"""
        self.select_first_element = self.driver.find_element(*self.select_first_locator)
        select = Select(self.select_first_element)
        select.select_by_index(1)

    def click_commercial_count(self):
        """点击商机-统计"""
        self.driver.find_element(*self.click_commercial_count_locator).click()

